-
Notifications
You must be signed in to change notification settings - Fork 957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return signing key in SignedEnvelope.payload #2522
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking this up! 🙏
/// It is the caller's responsibility to check that the signing key is what | ||
/// is expected. For example, checking that the signing key is from a | ||
/// certain peer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about enforcing this constraint via #[must_use]
? Something along the lines of the playground below:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh excellent! I was wondering if there was a way I could leverage #[must_use]
. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, unfortunately one can not do it on an anonymous tuple. E.g. instead of the additional struct
I would prefer to do:
fn foo() -> Result<(a, #[must_use] b), c> {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that was my first thought, but I hadn't considering using a struct instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, the above suggestion actually does not work. The compiler reports the field not being used in general, rather than not being used in this particular case.
Also nesting #[must_use]
structs doesn't work see rust-lang/rust#39524.
Also @MarcoPolo pointed out that users would likely do something along the lines of let (payload, _) = payload().handle_error();
which would thus circumvent the #[must_use]
.
Sorry for the noise here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do something like this: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=92e6fc6cf971873eb590d9ada72f85fa
But I am not sure if it is useful. Assigning _
will silence the must_use
warning ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately assigning the return value to anything and not using the key value will also satisfy the must_use lint. e.g. let data = foo().unwrap();
core/src/signed_envelope.rs
Outdated
/// | ||
/// It is the caller's responsibility to check that the signing key is what | ||
/// is expected. For example, checking that the signing key is from a | ||
/// certain peer. | ||
pub fn payload( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn payload( | |
pub fn payload_and_signing_key( |
What do you think of renaming the method as well? If I recall correctly you suggested this in your initial vulnerability report, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in ef3afcd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this!
I suggest we move forward and merge here. @MarcoPolo given that this is a breaking change, would you mind adding a changelog entry to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏
Context
Fixes #2511.
Another solution would be to pass in a closure as a key validation function to
payload
. I originally tried this, but quickly noticed that it made thePeerRecord
use case awkward. This is because the peer id we are validating against is inside the payload. So the closure would need access to the payload. If you passed in the payload to the closure, then you would need to parse the payload twice (or awkwardly mutate an outer variable).So instead, I return the signing key from the
payload
method.If I'm misunderstanding something @thomaseizinger please let me know.